package cn.itcast.leadnews.controller;
import cn.itcast.leadnews.common.PageResponseResult;
import cn.itcast.leadnews.common.ResponseResult;
import cn.itcast.leadnews.dto.WmNewsDTO;
import cn.itcast.leadnews.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "自媒体文章管理API",tags = "自媒体文章管理API")
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;
    @ApiOperation(value = "根据条件查询文章列表",notes = "根据条件 分页查询文章列表，将结果封装为通用分页结果返回")
    @PostMapping("/list")
    public PageResponseResult findAll(@RequestBody WmNewsDTO wmNewsDTO){
        return wmNewsService.findList(wmNewsDTO);
    }

    @ApiOperation(value = "根据id删除自媒体文章",notes = "逻辑删除  如果文章为 上架  并且  发布状态 不可以删除")
    @GetMapping("/del_news/{id}")
    public ResponseResult<Boolean> delNews(@PathVariable("id") Integer id) {
        return wmNewsService.delNews(id);
    }
    /**
     * 文章审核成功
     * @return
     */
    @ApiOperation(value = "审核通过 文章状态:4",notes = "根据id 将文章状态修改为4  考虑并发使用乐观锁方案修改")
    @PostMapping("/auth_pass/{newsId}")
    public ResponseResult<Boolean> authPass(@PathVariable Integer newsId) {
        return wmNewsService.updateStatus(4,newsId);
    }
    /**
     * 文章审核失败
     * @return
     */
    @ApiOperation(value = "审核失败 文章状态:2",notes = "根据id 将文章状态修改为2  考虑并发使用乐观锁方案修改")
    @PostMapping("/auth_fail/{newsId}")
    public ResponseResult<Boolean> authFail(@PathVariable Integer newsId) {
        return wmNewsService.updateStatus(2,newsId);
    }
}